using Microsoft.AspNetCore.Mvc;
using Nest;

namespace ElasticSearchDemo.Controllers
{
    [ApiController]
    [Route("[controller]")]
    public class WeatherForecastController : ControllerBase
    {
        private static readonly string[] Summaries = new[]
        {
        "Freezing", "Bracing", "Chilly", "Cool", "Mild", "Warm", "Balmy", "Hot", "Sweltering", "Scorching"
    };

        private readonly ILogger<WeatherForecastController> _logger;
        private readonly IElasticClient _elasticClient;
        private readonly IConfiguration _configuration;


        public WeatherForecastController(ILogger<WeatherForecastController> logger, IElasticClient elasticClient, IConfiguration configuration)
        {
            _logger = logger;
            _elasticClient = elasticClient;
            _configuration = configuration;
        }



        [HttpGet,Route("Search")]
        public async Task<dynamic> Search(string keyword)
        {
            var request = new SearchRequest
            {
                From = 0,
                Size = 20,
                Query = new MatchAllQuery()
            };

            var result = await _elasticClient.SearchAsync<dynamic>(request);

            return Ok(result.Documents);
        }

       
    }
    public class ESModel
    {
        public string Id { get; set; }

        public string Title { get; set; }

        public string Column { get; set; }

        public string Content { get; set; }

    }
}